VERSION=`git describe --tags`
BUILD=`date +%FT%T%z`
GIT_COMMIT=`git rev-list -1 HEAD`

if [[ "$1" != /* ]]; then
    echo "dist path $1 cannot use relative path use absolute instead"
    exit 1
fi

if [ -d "$1"  ]; then
    echo "dist path $1"
else
    echo "dist path $1 not exit, exit"
    exit 1
fi

docker run --rm -e DISTPATH=/dist/ -e APPVERSION=${VERSION} -e APPBUILDTIME=${BUILD} -e APPCOMMIT=${GIT_COMMIT} -e GOPROXY=https://goproxy.cn,direct -v "$PWD":/src -v $1:/dist -w /src golang:1.21.13 sh scripts/build_binary.sh
